import request, { postJson } from '@/apps/admin/utils/request';


export const deleteRoleResource = (resourceId: number) =>
    postJson(`${base}/deleteRoleResource`, {resourceId });


const base = '/v1/admin';

export const getRoles = () => request.get(`${base}/getRoles`);

export const addRole = (data: object) => postJson(`${base}/addRole`, data);

export const updateRole = (data: object) =>
    request.post(`${base}/updateRole`, data, {
        headers: { 'Content-Type': 'application/json' }
    }).then(res => res.data);

export const deleteRole = (roleId: number) =>
    request.post(`${base}/deleteRole`, { roleId });

export const getRolePermissions = () => request.get(`${base}/getPermissions`);

export const getRoleResources = (roleId: number) =>
    request.get(`${base}/getRoleResources?roleId=${roleId}`);

export const addResourcePermission = (roleId: number, type: string, resourceIndex: number) =>
    postJson(`${base}/addResourcePermission`, {roleId, type, resourceIndex });
